<?php

namespace Trawind\Extension\Traits;

use Illuminate\Database\Eloquent\Builder;


/**
 * @method Builder system()
 * @method Builder custom()
 * @method Builder defaultBusiness($businessTypeId)
 * @package namespace Trawind\Extension\Traits;
 */
trait CustomData
{

    public static $ID_THRESHOLD = 10000000;
    
    public static $ORIGIN_SYSTEM = 1;
    
    public static $ORIGIN_CUSTOM = 2;


    public static function getMaxId(): int
    {
        $maxId = static::custom()->max('id');
        $maxId < static::$ID_THRESHOLD and $maxId = static::$ID_THRESHOLD;
        return ++$maxId;
    }

    public function scopeSystem($query): Builder
    {
        return $query->where('origin_type_id', static::$ORIGIN_SYSTEM);
    }

    public function scopeCustom($query): Builder
    {
        return $query->where('origin_type_id', static::$ORIGIN_CUSTOM);
    }

    public function scopeDefaultBusiness($query,$businessTypeId): Builder
    {
        return $query->where('business_type_id', $businessTypeId)->where('is_default',1);
    }
}